Skip to content

Conversation

jorenham
Copy link
Member

@jorenham jorenham commented Sep 17, 2025

I heard that numpy_quaddtype has been growing lately, so I figured that it might be nice to have some static typing support. So here it is.

Mypy, stubtest, and pyright are all happy with it now (no errors are reported), even when they're run in strict mode.

To check for yourself, you can do something like

uv venv .venv
uv pip install mypy pyright numpy .
source .venv/bin/activate

To run stubtest (validates correctness of stubs by inspecting the runtime, and also runs mypy to type-check the stubs):

$ stubtest --mypy-config-file pyproject.toml numpy_quaddtype
Success: no issues found in 2 modules

To run type-check the stubs using pyright (in strict mode):

$ pyright
0 errors, 0 warnings, 0 informations

If you want to admire the juicy type coverage %:

$ pyright --ignoreexternal --verifytypes numpy_quaddtype
# output omitted since that would spoil the fun ;)

@jorenham jorenham added enhancement New feature or request numpy_quaddtype labels Sep 17, 2025
@SwayamInSync
Copy link
Member

LGTM

@SwayamInSync SwayamInSync merged commit 11a9ff7 into numpy:main Sep 17, 2025
7 checks passed
@jorenham jorenham deleted the quaddtype-typing branch September 18, 2025 04:36
Copy link
Contributor

@juntyr juntyr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should also have a CI step to verify these type stubs


#
def is_longdouble_128() -> bool: ...
def get_sleef_constant(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is wrong - we need an override for the function since it returns normal integers for the integer constants bits and precision

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yea of course; "bits" and "precision" return an int. I'll fix this in a follow-up.

And out of curiosity, why is this a function instead of "bare" constants?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We wanted to keep all definitions in the C(++) code so that Python only re-exports them

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Constants can be re-exported 🤷🏻

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean declaring the value a Python constant in the C++ code? That could be nice, though not something I'd know how to do

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea pretty much, but I'm not much of a C expert, so maybe I'm talking nonsense here. Although for the int ones it shouldn't be too difficult I'm guessing?

@juntyr
Copy link
Contributor

juntyr commented Sep 18, 2025

@jorenham @SwayamInSync I left some comments that should be addressed in a follow-up

jorenham added a commit to jorenham/numpy-user-dtypes that referenced this pull request Sep 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request numpy_quaddtype
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants